home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 14478 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.1 KB

  1. Path: mundook.cs.mu.OZ.AU!fjh
  2. From: fjh@mundook.cs.mu.OZ.AU (Fergus Henderson)
  3. Newsgroups: comp.lang.ada,comp.lang.c++
  4. Subject: Re: Iterators (was Re: some questions re. Ada/GNAT from a C++/GCC user)
  5. Date: 31 Mar 1996 18:36:19 GMT
  6. Organization: Comp Sci, University of Melbourne
  7. Message-ID: <4jmjb3$rbv@mulga.cs.mu.OZ.AU>
  8. References: <wnewmanDoxrCp.DKv@netcom.com> <Dp1oAw.7Cz@world.std.com> <EACHUS.96Mar29191146@spectre.mitre.org> <4jlmn5$h1k@Nntp1.mcs.net>
  9. NNTP-Posting-Host: mundook.cs.mu.oz.au
  10.  
  11. mikey@mcs.com (Mike Young) writes:
  12.  
  13. >eachus@spectre.mitre.org> says...
  14. >>The choice was between Ada and a shell script...I chose Ada:
  15. >>
  16. >>generic
  17. >>  with procedure To_Do(File: in String);
  18. >>procedure Iterate_Files(Pattern: in String := "*";
  19. >>                        Directory: in String := "");
  20. >>-- This generic iterates over all files in a directory matching Pattern and
  21. >>-- calls To_Do once for each such directory entry.  If a file has several
  22. >>-- links in the directory To_Do will be called once for each.
  23. >
  24. >=========
  25. >I don't know about that, Robert. The equivalent shell script would be:
  26. >
  27. >#---- iterateFiles
  28. >fileop=$1;shift
  29. >for file in $*; do $fileop $file; done
  30.  
  31. No, that shell script, like the vast majority of shell scripts around,
  32. is buggy.  Writing correct, portable shell scripts is actually pretty tricky.
  33.  
  34. Here's a better version:
  35.  
  36.     fileop="$1"; shift
  37.     case $# in
  38.         0) ;;
  39.         *) for file in "$@"; do $fileop "$file"; done ;;
  40.     esac
  41.  
  42. Now just be careful with the quoting when you invoke it...
  43.  
  44. > You are not restricted to procedures in that same program, all system
  45. > utilities are directly available, you don't need to rebuild to add new
  46. > features, and you need not have bothered with your 50 lines of code.
  47. > All are big wins, IMO.
  48.  
  49. Oh, certainly shell scripts are extremely useful. 
  50. But it helps to be aware of their drawbacks as well as their advantages.
  51.  
  52. --
  53. Fergus Henderson <fjh@cs.mu.oz.au>   |  "I have always known that the pursuit
  54. WWW: <http://www.cs.mu.oz.au/~fjh>   |  of excellence is a lethal habit"
  55. PGP: finger fjh@128.250.37.3         |     -- the last words of T. S. Garp.
  56.